package com.bestvike.stone.core.util.area;

import com.bestvike.linq.exception.ArgumentNullException;
import com.bestvike.stone.core.collection.KeyedCollection;
import org.springframework.util.Assert;

/**
 * 市级行政区集合
 * Created by 许崇雷 on 2018-07-28.
 */
public final class CityCollection extends KeyedCollection<String, City> {
    private final Province province;

    CityCollection(Province province) {
        Assert.notNull(province, "province can not be null");
        this.province = province;
    }

    @Override
    protected String getKeyForItem(City city) {
        return city.getCode();
    }

    @Override
    public boolean add(City city) {
        if (city == null)
            throw new ArgumentNullException("city");
        city.setProvince(this.province);
        return super.add(city);
    }
}
